home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / mailhand / metamail.z / metamail / bin / metasend < prev    next >
Encoding:
Text File  |  1992-05-05  |  5.8 KB  |  207 lines

  1. #!/bin/csh -f
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13. #
  14.  
  15. set MustDelete=0
  16. set batchmode=0
  17. set splitsize = 100000
  18. while ($#argv > 0)
  19.     switch ($1)
  20.         case "-S":
  21.             shift
  22.             if ($#argv == 0) then
  23.                 echo "-S requires a following argument, the SPLIT threshhold"
  24.                 exit
  25.             endif
  26.             set splitsize=$1
  27.             shift
  28.             breaksw
  29.         case "-b":
  30.             # Batch mode -- ALL args must be on command line
  31.             set batchmode = 1
  32.             shift
  33.             breaksw
  34.         case "-c":
  35.             shift
  36.             if ($#argv == 0) then
  37.                 echo "-c requires a following argument, the CC address"
  38.                 exit
  39.             endif
  40.             set cc=$1
  41.             shift
  42.             breaksw
  43.         case "-s":
  44.             shift
  45.             if ($#argv == 0) then
  46.                 echo "-s requires a following argument, the SUBJECT"
  47.                 exit
  48.             endif
  49.             set subject="$1"
  50.             shift
  51.             breaksw
  52.         case "-t":
  53.             shift
  54.             if ($#argv == 0) then
  55.                 echo "-t requires a following argument, the TO address"
  56.                 exit
  57.             endif
  58.             set to="$1"
  59.             shift
  60.             breaksw
  61.         case "-e":
  62.             shift
  63.             if ($#argv == 0) then
  64.                 echo "-e requires a following argument, the ENCODING value"
  65.                 exit
  66.             endif
  67.             set encode=$1
  68.             shift
  69.             breaksw
  70.         case "-f":
  71.             shift
  72.             if ($#argv == 0) then
  73.                 echo "-f requires a following argument, the DATA FILE"
  74.                 exit
  75.             endif
  76.             set datafile=$1
  77.             shift
  78.             breaksw
  79.         case "-m":
  80.             shift
  81.             if ($#argv == 0) then
  82.                 echo "-m requires a following argument, the MIME CONTENT-TYPE"
  83.                 exit
  84.             endif
  85.             set ctype=$1
  86.             shift
  87.             breaksw
  88.         case "-z":
  89.             set MustDelete=1
  90.             shift
  91.             breaksw
  92.         default:
  93.             echo UNRECOGNIZED METASEND OPTION: $1
  94.             exit
  95.     endsw
  96. end
  97.  
  98. if ($batchmode == 0) then
  99.     if (! $?to) then
  100.         echo -n "To: "
  101.         set to = $<
  102.     endif
  103.     if (! $?subject) then
  104.         echo -n "Subject: "
  105.         set subject = $<
  106.     endif
  107.     if (! $?cc) then
  108.         echo -n "CC: "
  109.         set cc = $<
  110.     endif
  111.     if (! $?ctype) then
  112.         echo -n "Content-type: "
  113.         set ctype = $<
  114.     endif
  115.     if (! $?datafile) then
  116.         getfile:
  117.         echo -n "Name of file containing $ctype data: "
  118.         set datafile = $<
  119.         if (! -e  $datafile) then
  120.             echo The file $datafile does not exist.
  121.             goto getfile
  122.         endif
  123.     endif
  124.     if (! $?encode) then
  125.         retry:
  126.         echo "Do you want to encode this data for sending through the mail?"
  127.         echo "  1 -- No, it is already in 7 bit ASCII"
  128.         echo "  2 -- Yes, encode in base64 (most efficient)"
  129.         echo "  3 -- Yes, encode in quoted-printable (less efficient, more readable)"
  130.         echo "  4 -- Yes, encode it using uuencode (not standard, being phased out)"
  131.         set encode=$<
  132.         switch ("$encode")
  133.             case 1:
  134.                 set encodingprog = cat
  135.       set encode = 7bit
  136.                 breaksw
  137.             case 2:
  138.                 set encodingprog = "mmencode -b"
  139.       set encode = base64
  140.                 breaksw
  141.             case 3:
  142.                 set encodingprog = "mmencode -q"
  143.       set encode = quoted-printable
  144.                 breaksw
  145.             case 4:
  146.                 set encodingprog = "uuencode $datafile"
  147.       set encode = x-uue
  148.                 breaksw
  149.             default:
  150.                 echo Unrecognized answer, please try again.
  151.                 goto retry
  152.         endsw
  153.     endif
  154. else
  155.     if (! $?to || ! $?subject || ! $?ctype || ! $?datafile) then
  156.         echo metasend: in batch mode, -t, -s, -f, and -m are all required
  157.         exit
  158.     endif
  159.     if (! -e  $datafile) then
  160.         echo metasend:  The file $datafile does not exist
  161.         exit
  162.     endif
  163.     if (! $?cc) set cc=""
  164.     if (! $?encode) then
  165.         if ("$ctype" =~ text*) then
  166.     set encodingprog = "mmencode -q"
  167.     set encode = "quoted-printable"
  168.         else
  169.             set encodingprog = "mmencode -b"
  170.             set encode = base64
  171.         endif
  172.     else if ($encode == "base64") then
  173.         set encodingprog = "mmencode -b"
  174.     else if ($encode == "x-uue") then
  175.         set encodingprog = "uuencode mail-body"
  176.     else if ($encode == "7bit") then
  177.         set encodingprog = cat
  178.     else
  179.         set encodingprog = "mmencode -q"
  180.         set encode = "quoted-printable"
  181.     endif
  182. endif
  183.  
  184. set fname = /tmp/metasend.$$
  185. echo "To: " "$to" > $fname
  186. echo "Subject: " "$subject" >> $fname
  187. echo "CC: " "$cc" >> $fname
  188. echo "MIME-Version: 1.0" >> $fname
  189. echo "Content-type: " $ctype >> $fname
  190. echo "Content-Transfer-Encoding: " $encode >> $fname
  191. echo  "" >> $fname
  192. $encodingprog < $datafile >> $fname
  193. # Ensure last line has trailing carraige return
  194. echo "" >> $fname
  195.  
  196. splitmail -s $splitsize -d $fname
  197. if (! $status) then
  198.     rm $fname
  199. else if ($MustDelete == 1) then
  200.     echo Mail delivery failed
  201.     rm $fname
  202. else
  203.     echo Mail delivery failed, draft mail is in $fname
  204. endif
  205.  
  206.